package com.badger.spring.cloud.alibaba.sentinel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;

/**
 * @EnableDiscoveryClient 开启服务注册和发现
 */
@SpringBootApplication
@EnableDiscoveryClient
public class SentinelApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SentinelApplication.class, args);
    }

    @RestController
    public class DemoController {

        @GetMapping(value = "/hello/{name}")
        @SentinelResource(value = "sayHello")
        public String apiHello(@PathVariable String name) {
            return "Hello, " + name;
        }

        @GetMapping("/demo")
        public String test() {
            return "demo";
        }
    }
}
